package com.luzhikun.ORMproject.db;

import java.sql.*;

/**
 * @Author Rookie Coder
 * @Description 数据库工具类
 * @Date
 **/
public class JDBCUtil {

    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }

    }

    /*
     * @Author liu-miss
     * @Description 连接数据库
     * @Date 17:41 2021/5/13
     * @Param []
     * @return java.sql.Connection
     **/
    public Connection getConnection() throws SQLException {
        String url="jdbc:mysql://localhost:3306/mvcsystem";
        String user="root";
        String psd="140489lu";
        Connection connection=null;
        if (connection==null) {
            connection=DriverManager.getConnection(url, user, psd);
        }
        return connection;
    }

    /*
     * @Author liu-miss
     * @Description 关闭操作
     * @Date 17:41 2021/5/13
     * @Param [connection, pst, rs]
     * @return void
     **/
    public void closeAll(Connection connection, PreparedStatement pst, ResultSet rs) throws SQLException {
        if (connection!=null){
            connection.close();
        }
        if (pst!=null){
            connection.close();
        }
        if (rs!=null){
            rs.close();
        }
    }



}
